package com.jackson.javabasereview.base;

/*
 * Author: JacksonCoder
 * FileName: TimeFormat
 * Version: 1.0.0
 * Date: 2025/8/14
 */

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class TimeFormat {

    public static void main(String[] args) {
        StringBuilder result = new StringBuilder();
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();

        // 1. 时间戳格式
        long timestamp = System.currentTimeMillis();
        result.append("时间戳: ").append(timestamp).append("\n");

        // 2. 格式化为 yy-MM-dd HH:mm:ss 格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yy-MM-dd HH:mm:ss");
        result.append("格式化时间: ").append(now.format(formatter)).append("\n");

        // 3. 东八区时间
        ZonedDateTime utcTime = now.atZone(ZoneId.of("UTC"));
        ZonedDateTime chinaTime = utcTime.withZoneSameInstant(ZoneId.of("Asia/Shanghai"));
        result.append("东八区时间: ").append(chinaTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss VV"))).append("\n");

        System.out.println(result.toString());
    }

}
